package sensoreColore;
import lejos.nxt.LCD;


public class LabyrinthTestColor {

	public static void main(String[] args) throws Exception {
		
		boolean trovato = false;
		
		int righelab = 16;
		int colonnelab = 12;
		
		LabyrinthSolver ls = new LabyrinthSolver(righelab,colonnelab);

		ls.calibra();

		ls.acquisisciMatrice();
//		ls.acquisisciMatrice2();

//		Thread.sleep(5000);

		ls.convertiMatrice(ls.getLabirinto());

		/*########## RICORDA #########
		 * # X=SCANDISCE COLONNE     #
		 * # Y=SCANDISCE RIGHE       #
		 * ###########################
		 * */
		
		/* v2 dell'esplora con xylist
		 * 
		 * */
		
		if(ls.getLunghezzaList() >= 2){
			LCD.clear();
			LCD.drawString("Elaborazione...", 0, 1);
//			for(int i = 0; !trovato && i < (ls.getLunghezzaList() - 1); i++){
//				for(int j = ls.getLunghezzaList() - 1; !trovato && j>=0 ; j--){
					//if (ls.esplora(ls.getX0(), ls.getY0(), ls.getX1(), ls.getY1())) {
//					if(i<j){
//						if (ls.esplora(ls.getXYList().get(i).getX(), ls.getXYList().get(i).getY(), ls.getXYList().get(j).getX(), ls.getXYList().get(j).getY())) {
						if (ls.esplora(ls.getXYList().get(0).getX(), ls.getXYList().get(0).getY(), ls.getXYList().get(1).getX(), ls.getXYList().get(1).getY())) {
							LCD.clear();
							LCD.drawString("Si Percorso", 0, 1);
							Thread.sleep(5000);
							trovato = true;
						} else {
							LCD.clear();
							LCD.drawString("No Percorso!", 0, 1);
							Thread.sleep(5000);
							trovato = false;
						}
//					}
//				}
//			}
		}
		else{
			LCD.clear();
			LCD.drawString("Labirinto non risolvibile", 0, 1);
		}
		 
		
		ls.riconvertiMatrice(ls.getLabirinto());

		ls.stampaMatriceInversa(ls.getLabirinto());

		Thread.sleep(2000);

		ls.riavvolgiMotore(ls.getAngle_y_rw(), ls.getRighe() + 1, ls.getSpeed_y_rw(), 0, ls.getMotore_y());
		
		if(trovato){
			
			ls.posizionaPenna();
			
			ls.drawLabyrinth();
		}

		// int[][] labirinto_={ {0,17,0,0,0,0,0,0,0,0,0,0},
		// {0,17,17,17,17,17,0,0,17,0,0,0},
		// {0,0,0,0,0,17,0,0,0,0,0,0},
		// {0,17,0,0,0,17,0,0,0,0,0,0},
		// {0,0,0,0,0,17,0,0,0,0,0,0},
		// {0,0,0,0,0,17,17,17,17,17,0,0},
		// {0,0,0,0,0,0,0,0,0,17,0,0},
		// {0,0,0,0,0,0,0,0,17,17,0,0},
		// {0,0,17,17,17,0,0,0,17,0,0,0},
		// {0,0,17,0,17,0,0,17,17,0,0,0},
		// {0,0,17,0,17,17,17,17,0,0,0,0},
		// {0,0,17,0,0,0,0,0,0,0,0,0},
		// {0,0,17,17,17,17,0,17,17,17,0,0},
		// {0,0,0,0,0,17,17,17,0,17,0,0},
		// {0,0,0,0,0,0,0,0,0,17,0,0},
		// {0,0,0,0,0,0,0,0,0,17,0,0} };
		// labirinto=labirinto_;
	}

}
